<?php
require_once 'includes/haut.php';
acces($niveau,0);

require_once 'includes/donneesFormulaires.php';
require_once 'modules/gestionReservation.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ma r&eacute;servation</title>
		<?php include('includes/headLinks.php');?>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/i18n/jquery-ui-i18n.min.js"></script>
		<script type="text/javascript" src="js/calendrier.js"></script>
		<script type="text/javascript" src="js/formReservation.js"></script>
	</head>
<body>

	<div id="entete">
		<?php include('includes/entete.php'); ?>
	</div>

	<div id="navigation">
		<?php include('includes/navigation.php'); ?>
	</div>

	<div id="principal">

	<?php if(isset($_GET["action"]) && $_GET["action"]!="supprimer") {
		$action = $_GET["action"];
	}
	if(($action=="modifier")) {
		$titre = "Modifier mes r&eacute;servations";
	}
	else if(($action=="ajouter")) {
		$titre = "Je r&eacute;serve !";
	}
	else  {
		header("Location:index.php");
		exit();
	}

	?>

		<form action="formReservation.php" method="post">
			<h2><?php echo $titre ;?></h2>
			
			<div class="info">
				<?php 
				if(isset($resaS)) {
					if($resaS['valide']){
						if($resaS['categorie']->getType()=="snow") 
							echo "Votre snow a &eacute;t&eacute; ajout&eacute; avec succ&egrave;s!</br>";
						else 
							echo "Votre paire de skis a &eacute;t&eacute; ajout&eacute;e avec succ&egrave;s!</br>";
					}
				}
				if(isset($resaC)) {
					if($resaC['valide']){
						echo "Vos chaussures ont &eacute;t&eacute; ajout&eacute;es avec succ&egrave;s!</br>";
					}
				}
				?>
			</div>
			

			<div class="error">

				<?php
				$err1 = '<div class="ui-state-error ui-corner-all">';
				$err2 = '</div>';
				if (isset($erreur) && $erreur!="")
				echo $err1.$erreur.$err2;
				if(isset($resaS)) {
					if(!$resaS['valide']){
						if($resaS['categorie']->getType()=="snow") 
							echo $err1.'Erreurs snow :</br>';
						else 
							echo $err1.'Erreurs skis :</br>';
						echo $resaS['erreursMat'];
						echo $resaS['erreursCat'];
						echo $resaS['erreursRes'];
						if(!isset($resaC) || (isset($resaC) && $resaC['valide'])){
							echo $err2;
						}
					}
// 						$materielS=$resaS['materiel'];
// 						$categorieS=$resaS['categorie'];
// 						$reservationS=$resaS['reservation'];
// 						$reservation=$resaS['reservation'];
				}
// 					else {
// 						$materielS = new materiel();
// 						$categorieS = new categorie();
// 						$reservationS = new reservation();
// 					}
				if(isset($resaC)) {
					if(!$resaC['valide']){
						if(!isset($resaS) || (isset($resaS) && $resaS['valide'])){
							echo $err1;
						}
						echo "Erreurs chaussures :</br>";
						echo $resaC['erreursMat'];
						echo $resaC['erreursCat'];
						echo $resaC['erreursRes'];
						echo $err2;
					}
// 						$materielC=$resaC['materiel'];
// 						$categorieC=$resaC['categorie'];
// 						$reservationC=$resaC['reservation'];
// 						$reservation=$resaS['reservation'];
				}
// 					else {
// 						$materielC = new materiel();
// 						$categorieC = new categorie();
// 						$reservationC = new reservation();
// 					}
// 					if(!isset($reservation))
// 						$reservationC = new reservation();

				?>
			</div>

			<div class = "champDate">
				<table>
					<tr>
						<th></th>
						<th>Dates de location</th>
					</tr>
					<tr>
						<td><label for="dateDebut">Du : </label></td>
						<td><input type="text" name="dateDebut" id="dateDebut"
							maxlength="10" value="<?php if (isset($dateD)) echo $dateD;?>" />
						</td>
					</tr>
					<tr>
						<td><label for="dateFin">Au : </label></td>
						<td><input type="text" name="dateFin" id="dateFin" maxlength="10"
							value="<?php if (isset($dateF)) echo $dateF;?>" /></td>
					</tr>
				</table>
			</div>

			<div class="champPrenom">
				<table>
					<tr>
						<th><label for="prenom">Pr&eacute;nom : </label></th>
						<td><input type="text" name="prenom" id="prenom" maxlength="30"
							value="<?php if (isset($prenom)) echo $prenom;?>" /></td>
					</tr>
				</table>
			</div>

			<table class="tabReservation">
				<tr>
					
					
				<?php echo ('<td>');
				foreach ($tabNiveau as $act=>$tabAct) {
					echo ('<table class="colReservation" id="'.$act.'">
								<caption>'.ucfirst($act).'</caption>');
					listeLogos($tabAct,$act);
					echo('</table>');
					if($act=="alpin")
					echo('</td><td>');
				}
				echo ('</td>');
				?>
				</tr>
			</table>

			<table id="formResa">
<!-- 				Jquery : contiendra les chechbox et select de choix de materiel -->
			</table>

			<p>
				<input type="hidden" name="action" value="<?php echo $action;?>" />
				<input id="activite" type="hidden" name="activite" value="" />
				<input id="niveau" type="hidden" name="niveau" value="" />
				<center> <input type="submit" name="envoyer" value="Envoyer" /> </center>
			</p>
		</form>

	</div>

	<script language="JavaScript">
		<?php if (isset($niveauJS)&&isset($actJS)) {?>
			var niveau = <?php echo $niveauJS; ?>;
			var act = <?php echo $actJS; ?>;
			$(document).ready(
					function() {
						initLogos(act,niveau);
			});
		<?php }
		if (isset($materielS) && !$resaS['valide']) {?>
			$(document).ready(
				function() {
					initMat("materielS");
			});
			<?php if(!empty($tailleS)){?>
				var tailleS =  <?php echo $tailleS; ?>;
				setTimeout("initSelect(\"tailleS\",tailleS)", 400);
				<?php if(!empty($marqueSJS)){?>
				var marqueS =  <?php echo $marqueSJS; ?>;
				setTimeout("initSelect(\"marqueS\",marqueS)", 600);
					<?php if(!empty($modeleSJS)){?>
					var modeleS =  <?php echo $modeleSJS; ?>;
					setTimeout("initSelect(\"modeleS\",modeleS)", 800);
		<?php }}}}
		if (isset($materielC) && !$resaC['valide']) {?>
			$(document).ready(
				function() {
					initMat("materielC");
				});
			<?php if(!empty($tailleC)){?>
				var tailleC =  <?php echo $tailleC; ?>;
				setTimeout("initSelect(\"tailleC\",tailleC)", 400);
	
				<?php if(!empty($marqueCJS)){?>
				var marqueC =  <?php echo $marqueCJS; ?>;
				setTimeout("initSelect(\"marqueC\",marqueC)", 600);
					<?php if(!empty($odeleCJS)){?>
					var modeleC =  <?php echo $modeleCJS; ?>;
					setTimeout("initSelect(\"modeleC\",modeleC)", 800);
		<?php }}}}?>
	</script>

	<div id="publicite">


	<?php include('includes/publicite.php'); ?>
	</div>

</body>
</html>

